/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DriverInterface2.java
 *
 * Created on 12-Mar-2012, 11:13:16
 */

/**
 *
 * @author matrosj0
 */

import java.awt.GridLayout;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JButton;

public class DriverInterface2 extends javax.swing.JFrame {
    //The id number of the driver
        private int driverID;
        //The name of the driver
        private String driverName;

        int noHolidays;


    /** Creates new form DriverInterface2 */
    public DriverInterface2(int driverID) {
        this.driverID = driverID;
        this.driverName = DriverInfo.getName(driverID);
        noHolidays = DriverInfo.getHolidaysTaken(this.driverID);
        
        setTitle("Driver home for: " + this.driverName);
        
        initComponents();
    }
    @Override
     public void dispose()
     {
        System.out.println("Closing");
        database.busDatabase.close();
        super.dispose();
     }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        holidayLabel = new javax.swing.JLabel();
        requestHolidayButton = new javax.swing.JButton();
        requestIllnessButton = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        holidayLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        holidayLabel.setText("You have had: " + noHolidays + " holidays.");
        holidayLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        requestHolidayButton.setText("Holiday");
        requestHolidayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                requestHolidayButtonActionPerformed(evt);
            }
        });

        requestIllnessButton.setText("Illness");
        requestIllnessButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                requestIllnessButtonActionPerformed(evt);
            }
        });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Welcome, " + this.driverName);
        jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabel2.setText("Request:");

        jButton1.setText("Cancel");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                    .addComponent(holidayLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(requestHolidayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(3, 3, 3)
                                .addComponent(requestIllnessButton, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(12, 12, 12)
                .addComponent(holidayLabel)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(requestHolidayButton)
                    .addComponent(requestIllnessButton))
                .addGap(17, 17, 17)
                .addComponent(jButton1)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void requestHolidayButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_requestHolidayButtonActionPerformed
        // TODO add your handling code here:
        System.out.println("Creating Holiday Interface");
        HolidayInterface hinterface = new HolidayInterface(this.driverID);
        hinterface.setVisible(true);
    }//GEN-LAST:event_requestHolidayButtonActionPerformed

    private void requestIllnessButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_requestIllnessButtonActionPerformed
        // TODO add your handling code here:
        System.out.println("Creating Illness Iterface");
        IllnessInterface illInterface = new IllnessInterface(this.driverID);
        illInterface.setVisible(true);
    }//GEN-LAST:event_requestIllnessButtonActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        database.openBusDatabase();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DriverInterface2(2068).setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel holidayLabel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton requestHolidayButton;
    private javax.swing.JButton requestIllnessButton;
    // End of variables declaration//GEN-END:variables

}
